﻿namespace com.stifel.BranchMgmt.WebParts.BranchView
{
    using System.Collections.Generic;
    using System.Reflection;
    using System.Web.UI.WebControls;

    using com.stifel.BranchMgmtDao;
    using com.stifel.Extensions.AssemblyExtensions;

    using Microsoft.SharePoint;

    public partial class BranchViewUserControl
    {
        #region Methods

        void loadPhotos( int branchId )
        {
            const string TARGETURL = "%target-url";
            const string TITLE = "%title";
            const string THUMBNAILURL = "%thumbnail-url";
            const string AUTHOR = "%author";
            const string COMMENTS = "%comments";
            const string PHOTOTYPE = "%phototype";

            const string TEMPLATE = "BranchViewUserControl_Photo.htm";

            string templatefqn = Assembly.GetExecutingAssembly( ).GetFullyQualifiedManifestResourceName( TEMPLATE );
            string template = Assembly.GetExecutingAssembly( ).GetManifestResourceAsString( templatefqn );

            StifelPhotoDao dao = new StifelPhotoDao( SPContext.Current.Web.Url );
            List<StifelPhoto> value = dao.GetByBranchLocation( branchId );

            foreach ( StifelPhoto o in value )
            {
                string s = template
                    .Replace( TARGETURL, o.URLPathFullUrl )
                    .Replace( TITLE, o.Title )
                    .Replace( THUMBNAILURL, o.ThumbnailURL )
                    .Replace( AUTHOR, o.PrimaryAuthor )
                    .Replace( COMMENTS, o.Comments )
                    .Replace( PHOTOTYPE, o.PhotoTypeTitle );

                uiPhoto.Controls.Add( new Literal
                {
                    Text = s
                } );
            }
        }

        #endregion Methods
    }
}